﻿using PetaPoco;
using Qy.Common;
using Qy.Models;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Qy.Repository
{
    [AppService]
    public class ContentCateRepository : BaseRepository<ContentCate, PetaPocoContext>
    {

        public ContentCateRepository(PetaPocoContext petaPocoContext) : base(petaPocoContext) { }


        /// <summary>
        /// 获取指定栏目列表 前台
        /// </summary>
        /// <returns></returns>
        public async Task<List<ContentCate>> CateListByIdAsync(string cid, bool type, string orderBy)
        {
            Sql sql = Sql.Builder;
            sql.Select("*")
               .From("qy_content_cate");

            if (cid != "0")
                sql.Where("Id IN (" + cid + ")");

            if (type)
                sql.Where("Type <> 1");

            sql.OrderBy(orderBy);

            return await CreateDAO().FetchAsync<ContentCate>(sql);
        }
    }
}
